package com.parse.c0003.starter;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.api.SigningService;
import com.parse.bean.SignDTO;
import com.parse.core.SignServiceImpl;
import com.parse.starter.R;
import com.parse.starter.R.id;
import com.parse.starter.R.layout;
import com.parse.util.Binder;

public class SigningActivity extends Activity {

	private SignDTO signDTO;
	private SigningService signingService;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.sign_layout);
		this.signingService = new SignServiceImpl();
		this.signDTO = new SignDTO();

//		new Binder<SignDTO>().init(this, //
//				SigningService.resource, //
//				this.signDTO);

		this.findViewById(R.id.signBtn).setOnClickListener(new signBtn());
		this.signDTO.addPropertyChangeListener(new FocusManagerListener());
		this.signDTO.setEmail("abc");

	}

	private class signBtn implements OnClickListener {

		@Override
		public void onClick(View v) {
			signingService.signin(signDTO, SigningActivity.this);
		}
	}

	public class FocusManagerListener implements PropertyChangeListener {

		@Override
		public void propertyChange(PropertyChangeEvent event) {
			String propertyName = event.getPropertyName();
			Toast.makeText(getApplicationContext(), propertyName,
					Toast.LENGTH_SHORT).show();
			// final View view = viewMap.get(propertyName);
			// if (view != null) {
			//
			// if (view instanceof EditText) {
			// EditText ed = (EditText) view;
			// ed.setText(event.getNewValue().toString());
			// } else if (view instanceof TextView) {
			// TextView ed = (EditText) view;
			// ed.setText(event.getNewValue().toString());
			// }
			// }

			// TODO Auto-generated method stub

		}
	}

}
